import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'

// 静态路由 所有人允许进入
export const staticRoutes: Array<RouteRecordRaw> = [
  {
    path: '/login',
    name: 'login',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '@/views/login/index.vue')
  },
  {
    path: '/',
    name: 'layout',
    component: () => import('@/views/layout/index.vue'),
  }
]


// 动态路由  需要角色权限
export const dynamicRoutes: Array<RouteRecordRaw> = [
  {
    path: '/home',
    name: 'home',
    component: () => import('@/views/home/index.vue'),
    meta: {
      role: 'user',
      title: '首页'
    },
  }, {
    path: '/user/list',
    name: 'userList',
    component: () => import('@/views/userList/index.vue'),
    meta: {
      role: 'user',
      title: '用户列表'
    },
  },{
    path: '/user/echars',
    name: 'echars',
    component: () => import('@/views/echars/index.vue'),
    meta: {
      role: 'user',
      title: '图标'
    },
  }, {
    path: '/user/manage',
    name: 'userManage',
    component: () => import('@/views/userManage/index.vue'),
    meta: {
      role: 'admin',
      title: '用户管理'
    },
  }]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes: staticRoutes
})

export default router
